<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
<meta charset="utf-8">
<meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport">
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="black" name="apple-mobile-web-app-status-bar-style">
<meta content="telephone=no" name="format-detection">
<meta content="email=no" name="format-detection">
<title>注册</title>
<link th:href="@{/clm/css/public/mui/mui.css}" rel="stylesheet"/>
<link th:href="@{/clm/css/zhuce.css}" rel="stylesheet"/>
<script th:src="@{/clm/js/public/jquery.min.js}"></script>
<script th:src="@{/clm/js/public/public.js}"></script>
<script th:src="@{/clm/js/public/mui/mui.min.js}"></script>
</head>
<body>
<div class="mui-content">
	<div class="top_logo">
		<img th:src="@{/clm/img/logo.png}" />
	</div>
	<div class="loginBox_contBox">
		<input type="hidden" id="recomphone" th:value='*{phone}'>
		<input type="hidden" id="id" th:value="${id}">
		<input type="hidden" id="baseUrl" th:value="${baseUrl}">
		<div class="loginBox_contBox_input">
			<input type="tel" id="phone" maxlength="11" placeholder="请输入手机号">
		</div>
		<div class="loginBox_contBox_input">
			<input type="number" class="forgotPassword_input1" id="valiCode" placeholder="请输入验证码">
			<div class="forgotPassword_input2">
				<a class="T-getCode" href="javascript:void(0);" onclick="sendMessage()" id="btnSendCode">发送验证码</a>
				<span class="T-getCode1"></span>
			</div>
		</div>
		<div class="loginBox_contBox_input">
			<input type="password"  id="password" maxlength="16" placeholder="请输入6-16登陆位密码" />
		</div>
		<button type="button"  class="loginBox_contBox_bnt registered_bnt" onclick="register()">免费注册</button>
	</div>
	<div class="zhuce_tishi">
		<p>
			<span>您的推荐人是：</span><span th:text=*{phone}></span>
		</p>
		<p>如果您是老会员，输入手机号获取验证码返回下载地址！</p>
	</div>
</div>
</body>
<script type="text/javascript">
mui.init({
	swipeBack:true
})
//获取短信验证码
$(function(){
    var validCode=true;
    $(".T-getCode").click (function  () {
        var time=60;
        var $code=$(this);
        if (validCode) {
            validCode=false;
            var t=setInterval(function  () {
                time--;
                $(".T-getCode").hide();
                $(".T-getCode1").show();
                $(".T-getCode1").html(time+"秒");
                if (time==0) {
                    clearInterval(t);
                    $(".T-getCode").html("重新获取");
		            $(".T-getCode1").hide();
                	$(".T-getCode").show();
                    validCode=true;
                }
            },1000)
        }
    })
})


//注册成功才能下载
var base = $("#baseUrl").val().trim();
function sendMessage() {
	var phone = $("#phone").val().trim();
	if (phone.length != 11) {
		mui.toast("请输入11位手机号码！",{duration:"long",type:"div"});
		return;
	}
	$.ajax({
		type : 'POST',
		url : base+"clm/sendSMS",
		data : {
			phone : phone
		},
		success : function(res) {
			if (res.apistatus == "200") {
				mui.toast("验证码发送成功！");
				return;
			} else if (res.apistatus == "300") {
				mui.toast("验证码发送成功！",{duration:"short",type:"div"});
				setTimeout(
						function() {
						window.location.href =base+"clm/jump";
						}, 1500);
			} else {
				mui.toast("验证码发送失败！",{duration:"long",type:"div"});
				return;
			}
		}
	});
}


function register() {
	var id = $("#id").val().trim();
	var phone = $("#phone").val().trim();
	var validate = $("#valiCode").val().trim();
	var passwd = $("#password").val().trim();
	var parentPhone = $("#recomphone").val().trim();
	if (phone.length != 11) {
		mui.toast("请输入11位手机号码！",{duration:"short",type:"div"});
		return;
	}
	if (validate.length == 0) {
		mui.toast("验证码不能为空！",{duration:"short",type:"div"});
		return;
	}
	if (passwd.length == 0) {
		mui.toast("密码不能为空！",{duration:"short",type:"div"});
		return;
	}
	if (passwd.length < 6) {
		mui.toast("密码长度至少为6位！",{duration:"short",type:"div"});
		return;
	}
	$.ajax({
		type : 'POST',
		url : base + "clm/saveRegister",
		data : {
			phone : phone,
			id:id,
			validate : validate,
			passwd : passwd,
			parentPhone : parentPhone
		},
		success : function(res) {
			if (res.status == "ZC") {
				mui.toast("验证码错误！",{duration:"short",type:"div"});
			} else if (res.status == "00") {
				mui.toast("注册成功！",{duration:"short",type:"div"});
				setTimeout(
						function() {
						window.location.href =base+"clm/jump";
						}, 2000);
				
			} else if (res.status == "ZD") {
				window.location.href =base+"clm/jump";
			} else if (res.status == "ZZ31") {
				mui.toast("推荐人不存在！",{duration:"short",type:"div"});
			} else if (res.status == "ZZ32") {
				mui.toast("推荐人手机号码不存在！",{duration:"short",type:"div"});
			} else {
				mui.toast("注册失败！",{duration:"short",type:"div"});
			}
		}
	});
}


</script>
</html>
